﻿@using Dignite.FileExplorer.Files;
@using Volo.Abp.AspNetCore.Components
@inherits AbpComponentBase

<Validation Validator="@(Validator ?? ValidationRule.None)" AsyncValidator="@AsyncValidator">
    <Button Color="Color.Primary" Clicked="OpenFileExplorerModalAsync">@L["SelectFile"]</Button>
    @if (FileDescriptorsContent != null)
    {
        @FileDescriptorsContent(FileDescriptors)
    }
    else
    {
        if (FileDescriptors != null && FileDescriptors.Any())
        {
            <Table>
                <TableHeader>
                    <TableRow>
                        <TableHeaderCell>@L["FileName"]</TableHeaderCell>
                        <TableHeaderCell>@L["FileSize"]</TableHeaderCell>
                        <TableHeaderCell></TableHeaderCell>
                    </TableRow>
                </TableHeader>
                <TableBody>
                    @foreach (var item in FileDescriptors)
                    {
                        <TableRow>
                            <TableRowCell>@item.Name</TableRowCell>
                            <TableRowCell>@FileSizeFormatter.FormatSize(item.Size)</TableRowCell>
                            <TableRowCell>
                                <Button Color="Color.Primary" Clicked="@(() => RemoveFileAsync(item))"><Icon Name="@IconName.Delete"></Icon></Button>
                            </TableRowCell>
                        </TableRow>
                    }
                </TableBody>
            </Table>
        }
    }
    <FileExplorerModal @ref="_fileExplorerModal" Multiple="@Multiple" SelectFiles="SelectFilesAsync"></FileExplorerModal>
</Validation>